package org.example.ReferenceType;

import java.lang.ref.SoftReference;

/**
 * - SoftReference: A soft reference is a reference that is cleared by the garbage collector in case of memory pressure.
 * 软引用：软引用是一种特殊的引用，在内存不足时，会被回收，但是它的强度比强引用要弱一些。
 * 主要用于缓存上
 */
public class T01_SoftReference {
    public static void main(String[] args) {
        SoftReference<byte[]> m = new SoftReference<>(new byte[1024 * 1024 * 10]);
        System.out.println(m.get());
        System.gc();
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(m.get());

        byte[] b = new byte[1024 * 1024 * 15];
        System.out.println(m.get());
    }
}
